package com.tan.controller;

import com.tan.entity.PageResult;
import com.tan.entity.Result;
import com.tan.pojo.Brand;
import com.tan.pojo.Goods;
import com.tan.service.IGoodsService;
import com.tan.vo.BrandQueryVo;
import com.tan.vo.GoodsQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tanMax
 * @since 2022-09-30
 */
@RestController
@RequestMapping("/goods")
public class GoodsController extends BaseController{
    @Autowired
    private IGoodsService goodsService;

    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(@RequestBody GoodsQueryVo vo, @PathVariable Integer currentPage, @PathVariable Integer pageSize){
        PageResult data = goodsService.search(currentPage,pageSize,vo);
        return toDataResult(data);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Goods goods){
        boolean save = goodsService.save(goods);
        return toResult(save);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id){
        boolean b = goodsService.removeById(id);
        return toResult(b);
    }
    @PutMapping
    public Result updateById(@RequestBody Goods goods){
        boolean b = goodsService.updateById(goods);
        return toResult(b);
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id) {
        Goods byId = goodsService.getById(id);
        return toDataResult(byId);
    }
}
